package com.hsmpay.utils;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

public class FileUtils {
	/**
	 * 获得文件字节数组
	 * 
	 * @param file
	 * @return
	 * @throws Exception
	 */
	public static byte[] getFileBytes(File file) throws Exception {
		InputStream is = null;
		byte[] resultButes = null;
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		try {
			is = new FileInputStream(file);// pathStr 文件路径
			byte[] b = new byte[1024];
			int n;
			while ((n = is.read(b)) != -1) {
				out.write(b, 0, n);
			}// end while
			resultButes = out.toByteArray();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				is.close();
				out.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		
		return resultButes;
	}
}
